<template>
  <!-- <div id="my_phone_type" :class="myPhone == 'ios' ? 'header_navbar_ios' : 'header_navbar_and'"> -->
  <div id="my_phone_type" class="header_navbar_and">
    <van-nav-bar
      :title="title"
      :left-text="leftText"
      :right-text="rightText"
      :left-arrow="leftArrow"
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />
  </div>
</template>
<script>
import { Toast } from 'vant';
export default {
  name: "navbar",
  props: {
    title: {
      type: String,
      default: "标题"
    },
    typePage: {
      type: String,
      default: ""
    },
    leftArrow: {
      type: Boolean,
      default: true
    },
    leftText: {
      type: String,
      default: "返回"
    },
    rightText: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      // 判断我的机型
      myPhone:''
    }
  },
  methods: {
    // 左侧返回按钮
    onClickLeft() {
      // 判断 header栏  是否返回原生页面
      if (this.title == "寻车" || this.title == "按揭" || this.title == "个人信息" || this.title == "设置"
           || this.title == "按揭记录" || this.title == "我的足迹"
          || this.title == "我的收藏" || this.title == "寻车统计" || this.title == "按揭意向统计"
          || this.title == "我的爱车" || this.title == "按揭意向管理" || this.title == "车辆详情"
          || this.title == "我的爱车" || this.title == "主播详情" || this.title == "主播列表" || this.title == "搜索" || this.title == '车煮用户协议' || this.title == '车煮隐私政策') {
        // h5与uniapp的交互 => 点击返回上一页
        if (window.UniAppJSBridge) {
          uni.postMessage({
            data:{
              type:5,
            }
          })
        }
      }else if(this.title == "寻车信息" || this.title == "寻车记录"){
        // h5与uniapp的交互 => 点击返回上一页
        if (window.UniAppJSBridge) {
          uni.postMessage({
            data:{
              type:6,
              path:'center'
            }
          })
        }
      }else if (this.title == "寻车详情"){
        if (this.typePage == '寻车记录') {
          /* this.$router.push({
            path:'/findcar/findCarRecord'
          }) */
          if (window.UniAppJSBridge) {
          uni.postMessage({
            data:{
              type:5
            }
          })
        }
        }else if(this.typePage == '寻车管理'){
          this.$router.push({
            path:'/findcar/findCarManagement'
          })
        }else if(this.typePage == '生成订单'){
          this.$router.go(-1)
        }
      }else if(this.title == "购车事项通知书"){
        localStorage.removeItem("editBuyCarNotification");
        this.$router.go(-1);
        
      }else {
        this.$router.go(-1);
      }
    },
    // 右侧更多操作按钮
    onClickRight() {
      if (this.title == "选择车型"){
        if (this.typePage == '编辑购车事项通知书') {
          this.$router.push({
            path:'/form/searchBrand',
            query:{
              myName:'editBuyCarNotification'
            }
          })
        } else if (this.typePage == '新建爱车') {
          this.$router.push({
            path:'/form/searchBrand',
            query:{
              myName:'/myCar/add'
            }
          })
        } else if (this.typePage == '新增寻车') {
          this.$router.push({
            path:'/form/searchBrand',
            query:{
              myName:'FindCarForm'
            }
          })
        } else if (this.typePage == '新增按揭') {
          this.$router.push({
            path:'/form/searchBrand',
            query:{
              myName:'MortageForm'
            }
          })
        } else{
          this.$router.push({
            path:'/form/searchBrand'
          })
        }
      }else if (this.title == "我的爱车") {
        this.$router.push({
          name:'addCar',
          query: {
            status: 0 // 0为添加
          }
        })
      }
    },
    //获取当前环境
    getEnvironment() {
      let u = navigator.userAgent;
      let isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android终端
      let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
      // android();
      if (isAndroid) {
        this.myPhone = 'android'
		    let immersed = 0;
		    let ms=(/Html5Plus\/.+\s\(.*(Immersed\/(\d+\.?\d*).*)\)/gi).exec(navigator.userAgent);
		    if(ms&&ms.length>=3){ // 当前环境为沉浸式状态栏模式
		    immersed=parseFloat(ms[2]);// 获取状态栏的高度
		    }
        /* Toast("（test）状态栏高度为："+immersed) */
        this.$nextTick(()=>{
          document.getElementById("my_phone_type").style.paddingTop = `${immersed}px`
        })
		    // return immersed;
      }
      if (isIOS) {
        this.myPhone = 'ios'
      }
    }
  },
  created() {
    // this.getEnvironment()
	},
};
</script>
<style scoped lang="less">
/* #my_phone_type{
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  margin-bottom: 50px;
} */
.header_navbar_and {
  // padding-top: 50px;
  height: 46px;
  overflow: hidden;
  // background-color: #5076b8;
  .van-hairline--bottom::after {
    // border-color: #5076b8 !important;
  }
}.header_navbar_ios {
  height: 46px;
  overflow: hidden;
  // background-color: #5076b8;
  .van-hairline--bottom::after {
    // border-color: #5076b8 !important;
  }
}
</style>
<style lang="less">
.header_navbar_and{
  .van-nav-bar .van-icon{
    color: #000000;
  }
  .van-nav-bar__text{
    color: #000000;
  }
  /* .van-nav-bar__text{
    color: #000000;
    font-family: PingFangSC-Regular, PingFang SC ;
    font-weight: 400;
    font-size: 16px;
  }
  .van-nav-bar__title{
    color: #000000;
    font-family: PingFangSC-Regular, PingFang SC ;
    font-weight: 400;
    font-size: 16px;
  } */
}
.header_navbar_ios {
  .van-nav-bar .van-icon{
    color: #000000;
  }
  .van-nav-bar__text{
    color: #000000;
  }
}
</style>
